package com.honey.solr.daosupport.method;

import com.honey.compilation.java.IfBlock;
import com.honey.compilation.java.JavaVisibility;
import com.honey.compilation.java.Method;
import com.honey.compilation.java.MethodDecoration;
import com.honey.compilation.java.Parameter;
import com.honey.core.builder.CharacterBuilder;
import com.honey.core.builder.CharacterBuilderFactory;
import com.honey.core.compiler.IndentSpace;
import com.honey.core.types.FullyQualifiedJavaType;
import com.honey.core.types.JDKFullyQualifiedJavaType;
import com.honey.generator.java.AbstractClassName;

public class LikeMethod extends AbstractClassName {

	public Method createMethod(){
		Method answer = new Method("like");
		answer.addJavaDocLine("Lucene的模糊查询格式是 field:value");
		MethodDecoration methodDecoration = answer.getDecoration();
		methodDecoration.setVisibility(JavaVisibility.PRIVATE);
		methodDecoration.setFinal(true);
		answer.setReturnType(new FullyQualifiedJavaType("StringBuilder"));
		Parameter parameter = new Parameter("Enum<?>","name");parameter.addJavaDocLine("查询字段的名称");
		answer.addParameter(parameter);
		parameter = new Parameter(JDKFullyQualifiedJavaType.getStringInstance(),"value");
		answer.addParameter(parameter);parameter.addJavaDocLine("值");
		
		answer.addBodyLine("StringBuilder answer = new StringBuilder();");
		IfBlock ifblock = new IfBlock("value == null || value.length()==0");
		ifblock.addBodyLine("value =\"*\"");
		answer.addBlocks(ifblock);

		answer.addBodyLine("return answer.append(name).append(':').append(value)");
		return answer ;
	}
}
